/**
 * 配置参考:
 * https://cli.vuejs.org/zh/config/
 */

// const url = 'http://472x04y747.zicp.vip';
// const imgBaseUrl = 'http://mf.dev.gientech.com:7442/';
const url = 'http://183.60.98.92:8888/';
const imgBaseUrl = 'http://183.60.98.92:8888/';
const CompressionWebpackPlugin = require('compression-webpack-plugin');

module.exports = {
    lintOnSave: true,
    productionSourceMap: false,
    chainWebpack: (config) => {
        config.plugin('html').tap((args) => {
            const date = new Date();
            args[0].createDate = date;
            return args;
        });
        config.plugin('compressionPlugin').use(
            new CompressionWebpackPlugin({
                test: /\.(js|css|svg|woff|ttf|json|html)$/, /// 匹配文件名
                threshold: 10240, //对超过10k的数据压缩
                deleteOriginalAssets: false // 不删除源文件
            })
        );
        // 忽略的打包文件
        config.externals({
            axios: 'axios'
        });
        const entry = config.entry('app');
        entry.add('babel-polyfill').end();
        entry.add('classlist-polyfill').end();
    },
    // 配置转发代理
    devServer: {
        disableHostCheck: true,
        port: 8080,
        proxy: {
            '/mfs': {
                target: imgBaseUrl, //图片代理
                ws: false, // 需要websocket 开启
                pathRewrite: {
                    '^/mfs': '/mfs'
                }
            },
            '/': {
                target: url,
                ws: false, // 需要websocket 开启
                pathRewrite: {
                    '^/': '/'
                }
            }
            // 3.5 以后不需要再配置
        }
    },
    configureWebpack: {
        devtool: 'source-map'
    },
    css: {
        loaderOptions: {
            postcss: {
                plugins: [
                    require('postcss-pxtorem')({
                        rootValue: 18, // 换算的基数
                        selectorBlackList: [], // 忽略转换正则匹配项 列入一些ui库, ['.el'] 就是忽略elementUI库
                        propList: ['*']
                    })
                ]
            }
        }
    }
};
